package wang.conge.javasedemo.core.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CallAndFutureTest {

	public static void main(String[] args) {
		ExecutorService exec = Executors.newFixedThreadPool(2);
		
		Future<Integer> future = exec.submit(new Callable<Integer>() {

			@Override
			public Integer call() throws Exception {
				System.out.println("call");
				return 2;
			}
		});
		
		try {
			System.out.println(future.get());//阻塞获取结果
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
		
		exec.shutdown();
	}

}
